package top.kaoshanji.p1ch03b;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import top.kaoshanji.u1constant.FileConstant;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.DosFileAttributeView;
import java.nio.file.attribute.DosFileAttributes;

/**
 * 代码清单 p1ch03b-08：文件属性视图的使用示例
 * author kaoshanji
 * ^_^
 * create time 2025/1/10 20:57
 */
public class FileAttributesExample01 {

    private static final Logger logger = LogManager.getLogger(FileAttributesExample01.class);

    public static void main(String[] args) throws IOException {
        logger.info("...代码清单 p1ch03b-08：文件属性视图的使用示例...");

        Path path = Paths.get(FileConstant.LOCAL_ROOT_PATH.concat("深入理解Java7：核心技术与最佳实践-成富-随书源码.7z"));

        // 需要在 windows 系统下运行
        DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class);
        if (view != null) {
            DosFileAttributes attributes = view.readAttributes();
            System.out.println(attributes.isReadOnly());
        }


    }

}
